﻿#region 命名空间

using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;
using WinnerCMS.Model.Attribute;

#endregion

namespace WinnerCMS.WebUI.Admin.Model
{
    [Access("257002,257003")]
    public partial class Manage : WebFactory.PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindList();
            }
        }

        public void BindList()
        {
            this.GV_List.DataSource = new ModelManage().GetList();
            this.GV_List.DataBind();
        }


        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var ID = this.GV_List.DataKeys[e.Row.RowIndex].Value.ToString();
                var tc = e.Row.Cells[2];
                var lb = (HyperLink) tc.Controls[0];
                lb.Attributes.Add("onclick",
                    string.Format("return NewTabPage('{0}_{1}','{2}');", lb.Text, ID, lb.NavigateUrl));
                lb.NavigateUrl = "#";
            }
        }


        protected void GV_List_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var res = PolicyInjection.Create<ModelManage>().Delete((byte) this.GV_List.DataKeys[e.RowIndex].Value);
            if (res.Errors.Length > 0)
            {
                MsgBox.Message(res.Errors, this.UpdatePanel1);
            }
            else
            {
                MsgBox.Message("删除成功,请自行删除相关对象！", this.UpdatePanel1);

                BindList();
            }
        }
    }
}